package com.example.design.config;

import com.example.design.service.Strategy;
import com.example.design.service.StrategyRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author Hong Qiang
 * @Date 2023/3/10 16:20
 * @Version 1.0
 */
@Configuration
public class StrategyConfig {

    @Bean
    public StrategyRunner runner(List<Strategy> strategies) {
        Map<String, Strategy> strategyMap = strategies.stream().collect(Collectors.toMap(Strategy::strategy, s -> s));
        return flag -> strategyMap.get(flag).algorithm();
    }
}
